<template>
	<view class="form-container">
		<!-- form演示 -->
		<view class="form-group">
			<form class="form-main">
				<view class="form-group">
					<h3>旧托盘</h3>
					<view><input id="inputOld" :focus="focus1" name="inputold" type="number" @input="INPUT" v-model="model.oldBarCode"
							placeholder="旧托盘编号" />
					</view>
				</view>

				<view class="form-group">
					<h3>新托盘</h3>
					<view><input id="inputNew" :focus="focus2" name="inputnew" type="number" v-model="model.newBarCode"
							placeholder="新托盘编号" /></view>
				</view>
				<!-- 新增button按钮触发submit事件 -->
				<view class="form-group"><button class="btnsubmit" @click="deterMine" form-type="submit">确定</button>
				</view>
				<view class="form-group"><button type="default" form-type="reset">重置</button></view>
			</form>
		</view>
	</view>
</template>

<script>
	import {
		PalletExchange
	} from '@/api/pda.js';
	import {
		warn
	} from "vue";
	export default {
		data() {
			return {
				fetching: false,
				labelPosition: 'top',
				errorType: ['message'],
				border: false,
				model: {
					oldBarCode: '',
					newBarCode: ''
				},
				//屏幕高度
				screenHeight: 0,
				focus1: true,
				focus2: false,
				timer:null
			}
		},
		onLoad() {
			this.screenHeight = uni.getSystemInfoSync().windowHeight;
		},
		methods: {
			deterMine() {
				uni.request({
					/* 网页 调试接口 */
					//url: 'http://127.0.0.1:5000/PDA/PalletExchange',

					/* Android 调试接口 */
					//url: 'http://10.5.64.102:5000/PDA/PalletExchange',
					url: this.$global.url1+':5000/PDA/PalletExchange',
					method: 'POST',
					sslVerify: false,
					data: {
						"oldBarCode": this.model.oldBarCode,
						"newBarCode": this.model.newBarCode,
					},
					header: {
						"Content-Type": "application/json; charset=UTF-8"
						// 'content-type':'application/x-www-form-urlencoded'
					},
					success: (res) => {
						if (res.statusCode == 200) {
							uni.showToast({
								icon: 'success',
								title: '修改成功',
								mask: true,
							});
							this.model.newBarCode=null;
							this.model.oldBarCode=null;
						} else {
							uni.showToast({
								icon: 'error',
								mask: true,
								title: "修改失败",
							})
						}
					},
					fail: (res) => {
						uni.showToast({
							icon: 'error',
							mask: true,
							title: "接口请求失败!",
						})
						console.log("error===" + res.errMsg)
					}
				})
			},
			INPUT(e) {
				// setInterval(()=>{
				// 	if (e.detail.value.length == 4) {
				// 		this.focus1 = false,
				// 		this.focus2 = true
				// 	}
				// 	console.log(111)
				// },200)
				console.log(e.detail.value)
				if (e.detail.value.length == 4) {
					this.focus1 = false,
						this.focus2 = true
				}
			},
			
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #EEF0F4;
		font-size: 18px;
	}

	u-button {
		float: left;
		display: inline;
	}

	.form {
		margin-top: 35rpx;
		width: 100%;
		padding: 0 20rpx;
	}

	.form-group {

		padding: 20rpx 30rpx 0rpx 30rpx;
	}

	.btnsubmit {
		margin-top: 50px;
	}

	#user-insert-line::before {
		position: absolute;
		right: 25px;
		bottom: 0;
		top: 5rem;
		left: 40px;
		height: 1px;
		content: '';
		-webkit-transform: scaleY(.5);
		transform: scaleY(.5);
		background-color: #c8c7cc;
	}

	#name::before {
		position: absolute;
		right: 25px;
		bottom: 0;
		top: 8.8rem;
		left: 40px;
		height: 1px;
		content: '';
		-webkit-transform: scaleY(.5);
		transform: scaleY(.5);
		background-color: #c8c7cc;
	}
</style>
